package sz.com.battleship.game.GameElement;

import java.io.Serializable;
import java.util.HashSet;

public class Ship implements Serializable
{
	/**
	 * 
	 */
	private static final long serialVersionUID = -8866731985297829583L;
	//type 0 = BattleCruiser, type 1 = Carrier, type 2 = Medivac, type 3 = Phoenix, type 4 = Viking
	private final int type_; //the type of the ship as described above
	private int hits_ = 0;
	private final HashSet<Integer> boardSpaces_; //Position used by ship on grid
	
	//Ship sizes used by ship factory
	public static final int battlecruiserSize = 5;
	public static final int battlecruiserType = 0;
	
	public static final int carrierSize = 4;
	public static final int carrierType = 1;
	
	public static final int medivacSize = 3;
	public static final int medivacType = 2;
	
	public static final int phoenixSize = 3;
	public static final int phoenixType = 1;
	
	public static final int vickingSize = 2;
	public static final int vickingType = 0;
	
	public Ship(int type, HashSet<Integer> boardSpaces) 
	{
		type_ = type;
		boardSpaces_ = boardSpaces;
		if (type == 0)
		{
			hits_ = 5; //BC
		}
		else if (type == 1)
		{
			hits_ = 4; //carrier
		}
		else if (type == 2)
		{
			hits_ = 3; //medivac
		}
		else if (type == 3)
		{
			hits_ = 3; //phoenix
		}
		else if (type == 4)
		{
			hits_ = 2; //viking
		}
	}

	public boolean takeHits()
	{
		hits_--;
		if (hits_ <= 0)
		{
			return true; //Ship has been sinked
		}
		return false; //ship is not dead yet
	}
	
	//Get size of ship type 
	public static int getSize(int type)
	{
		int i = -1;
		switch(type)
		{
		case 0:
			i = Ship.battlecruiserSize;
			break;
		case 1:
			i = Ship.carrierSize;
			break;
		case 2: 
			i = Ship.medivacSize;
			break;
		case 3:
			i = Ship.phoenixSize;
			break;
		case 4:
			i = Ship.vickingSize;
			break;
		}	
		return i;
	}
	
	//Get hits of current ship object
	public int getHits() {
		return hits_;
	}

	public HashSet<Integer> getBoardSpaces_() {
		return boardSpaces_;
	}
	
	//Get name of current ship object
	public String getName()
	{
		switch(type_)
		{
		case 0:
			return "BattleCruiser";
		case 1:
			return "Carrier";
		case 2: 
			return "Medivac";
		case 3:
			return "Phoenix";
		case 4:
			return "Viking";
		}
		return "invalid type";
	}

	public static String getName(int type)
	{
		switch(type)
		{
		case 0:
			return "BattleCruiser";
		case 1:
			return "Carrier";
		case 2: 
			return "Medivac";
		case 3:
			return "Phoenix";
		case 4:
			return "Viking";
		}
		return "invalid type";
	}
	
	public int getType()
	{
		return type_;
	}
}

